package GUI; //done

import java.awt.HeadlessException;
import java.awt.Rectangle;
import java.awt.SystemColor;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import Client.ClientAbstractWindow;
import Common.Settings;
import Entities.CustomerContactEmployee;

/**
 * This Class controls customer contact employee menu.
 * @author waleed
 * @author kamel
 * @author ameer
 * @author bshara
 */
public class CustomerContactEmployeeMenu extends ClientAbstractWindow{
	/** The serial Version UID. */
	private static final long serialVersionUID = 1L;

	/** The add customer Button. */
	private JButton addCustomerButton = null;
	
	/** The update customer Button. */
	private JButton updateCustomerButton = null;
	
	/** The add customer interests Button. */
	private JButton updateCustomerInterestsButton;
	
	/** The customer contact employee user. */
	private CustomerContactEmployee customercontactemployee  = null;
	
	/** The title picture Label. */
	private JLabel label_1;
	
	/** The Background picture Label. */
	private JLabel BackgroundLabel;
	
	/**
	 * Default constructor
	 */
	public CustomerContactEmployeeMenu() {
		super();
		setBackground(SystemColor.activeCaption);
		initialize();	
	}
	
	/**
	 * This function initializes customer contact employee Menu
	 */
	private void initialize(){
		customercontactemployee = new CustomerContactEmployee();
		this.setSize(600, 457);
		this.setLayout(null);
		getUsernameLabel().setText("Welcome "+Settings.Logged_Username);
		add(getBtnUpdateCustomerInterests());
		this.add(getAddCustomerButton(),null);
		this.add(getUpdateCustomerButton(),null);
	
		label_1 = new JLabel("");
		label_1.setIcon(new ImageIcon(LoginMenu.class.getResource("/Pictures/Customer-icon.png")));
		label_1.setBounds(65, 49, 300, 72);
		this.add(label_1);
		
		BackgroundLabel = new JLabel("");
		BackgroundLabel.setIcon(new ImageIcon(CustomerContactEmployeeMenu.class.getResource("/Pictures/bg.png")));
		BackgroundLabel.setBounds(0, -320, 678, 777);
		this.add(BackgroundLabel);
	}
	
	/**
	 * This function initializes AddCustomerButton
	 */
	private JButton getAddCustomerButton(){
		if (addCustomerButton == null){
			addCustomerButton = new JButton();
			addCustomerButton.setBounds(new Rectangle(65, 176, 199, 29));
			addCustomerButton.setText("Add Customer");
			addCustomerButton.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed(java.awt.event.ActionEvent e){			
					customercontactemployee.addCustomer();
				}
			});
		}
		return addCustomerButton;
	}
	
	/**
	 * This function initializes UpdateCustomerButton
	 */
	private JButton getUpdateCustomerButton(){
		if (updateCustomerButton == null){
			updateCustomerButton = new JButton();
			updateCustomerButton.setBounds(new Rectangle(65, 239, 199, 29));
			updateCustomerButton.setText("Update Customer");
			updateCustomerButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {			
					customercontactemployee.UpdateCustomer();
				}
			});
		}
		return updateCustomerButton;
	}
	
	/**
	 * This function initializes BtnUpdateCustomerInterests
	 */	
	private JButton getBtnUpdateCustomerInterests(){
		if (updateCustomerInterestsButton == null) {
			updateCustomerInterestsButton = new JButton();
			updateCustomerInterestsButton.setText("Update Customer Interests");
			updateCustomerInterestsButton.setBounds(new Rectangle(200, 150, 450, 6));
			updateCustomerInterestsButton.setBounds(65, 299, 199, 29);
			updateCustomerInterestsButton.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed(java.awt.event.ActionEvent e){			
					try{
						CustomerSearchWindow customersearch = new CustomerSearchWindow("AddCustomerInterests");
						customersearch.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE);
						customersearch.setBounds(500,200,400, 300 ); // set frame size
						customersearch.setVisible( true ); // display frame
					}
					catch(HeadlessException headlessexception){
						JOptionPane.showMessageDialog(null, "FATAL ERROR","",JOptionPane.ERROR_MESSAGE);
					}	
				}
			});
		}
		return updateCustomerInterestsButton;
	}
}
